import cv2
import numpy as np

img = cv2.imread('3/lena_gray.jpg', 0)
mask1 = np.ones(img.shape, dtype=np.uint8) * 254

imgH7 = cv2.bitwise_and(img, mask1)

img1 = cv2.imread('4/treasure1.jpg', 0)

x, y = img1.shape
img2 = cv2.resize(img1, [y, x])

img2[img2 < 100] = 0
img2[img2 > 99] = 1

img_watermask = cv2.bitwise_or(imgH7, img2)
cv2.imshow("original image", img)
cv2.imshow("watermark Image", img_watermask)

extract_mask = np.ones(img.shape, dtype=np.uint8)
watermask = cv2.bitwise_and(img_watermask, extract_mask)
watermask[watermask>0] = 255

cv2.imshow("extrated_watermask", watermask)

cv2.waitKey(0)
cv2.destroyAllWindows()